package org.example;


import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Controller;

import java.lang.reflect.Array;
import java.util.Arrays;

@Aspect
@Controller
public class LoggerAspect {
    @Before("execution(public int org.example.CalImpl.*(..))")
    public void before(JoinPoint joinPoint) {
        String name = joinPoint.getSignature().getName();
        String args = Arrays.toString(joinPoint.getArgs());
        System.out.println(name + "的参数是:" + args);
    }
    @After("execution(public int org.example.CalImpl.*(..))")
    public void after(JoinPoint joinPoint) {
        String name=joinPoint.getSignature().getName();
        System.out.println(name+"方法结束");
    }
    @AfterReturning(value = "execution(public int org.example.CalImpl.*(..))",returning = "result")
    public void afterReturn(JoinPoint joinPoint,Object result){
        String name=joinPoint.getSignature().getName();
        System.out.println(name+"方法的结果是"+result);
    }
    @AfterThrowing(value = "execution(public int org.example.CalImpl.*(..))",throwing = "ex")
    public void afterThrowing(JoinPoint joinPoint,Exception ex){
        String name=joinPoint.getSignature().getName();
        System.out.println(name + "方法抛出异常" + ex);
    }
} 